﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace PloobsEngine.SceneControl
{
    public class NoisePostEffect : IPostEffect
    {
        #region IPostEffect Members
        EngineStuff engine;
        private Effect noise;
        private float m_Timer = 0;
        private SpriteBatch spriteBatch;

        public void init(EngineStuff engine)
        {
            this.engine = engine;
            this.noise = EngineStuff.InternalContentManager.GetAsset<Effect>("noise");
            spriteBatch = EngineStuff.SpriteBatch;
        }

        public void Draw(IRenderHelper rHelper, Microsoft.Xna.Framework.GameTime gt, Microsoft.Xna.Framework.Rectangle screenRec, IWorld world)
        {
            m_Timer += (float)gt.ElapsedGameTime.Milliseconds / 500;

            spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            {
                // Apply the post process shader
                noise.Begin();
                {
                    noise.CurrentTechnique.Passes[0].Begin();
                    {
                        noise.Parameters["fTimer"].SetValue(m_Timer);
                        noise.Parameters["iSeed"].SetValue(1337);
                        noise.Parameters["fNoiseAmount"].SetValue(0.01f);
                        spriteBatch.Draw(rHelper[PrincipalConstants.CurrentImage], screenRec, Color.White);
                        noise.CurrentTechnique.Passes[0].End();
                    }
                }
                noise.End();
            }
            spriteBatch.End();
            
        }

        #endregion
    }
}
